using Model.Pizza;
using Autofac;
using Microsoft.AspNetCore.Mvc;
using UserService;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddCors(
    c => c.AddPolicy("any",
    p => p.AllowAnyHeader()
          .AllowAnyMethod()
          .AllowAnyOrigin()));
builder.Services.AddSingleton<UserService.IUserService, UserService.UserService>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}


/// <summary>
/// CORS总开关
/// </summary>
app.UseCors("any");

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.MapGet("/minapi", () =>
{
    return "Hello world!";
});
app.MapPost("/minapi", (Pizza data) =>
{
    return data;
});
app.MapGet("/minapi/1", delegate ()
{
    Console.WriteLine("Delegate used!");
});
app.MapPost("/test", (UserService.IUserService userService) =>
{
    return userService;
});

app.Run();
